package com.hzy.seatastorage.storage.service.impl;

import com.hzy.seatastorage.storage.dao.StorageMapper;
import com.hzy.seatastorage.storage.service.StorageService;
import com.hzy.storage.entities.Storage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 这里填写描述
 * 填写修改说明
 *
 * @author hzy
 * @version Revision:v1.0
 * @since Date:2022-03-15 17:06
 */
@Slf4j
@Service
public class StorageServiceImpl implements StorageService {

    @Resource
    private StorageMapper storageMapper;

    @Override
    public Storage decrease(String productId, Integer count) {
        log.info("----------> 扣减库存开始, productId:{}, count:{}", productId, count);
        Storage storage = storageMapper.selectByProductCode(productId);
        storage.setCount(storage.getCount() - count);
        int result = storageMapper.updateByPrimaryKey(storage);
        log.info("----------> 扣减库存结束:{}, {}", result, storage);

//        log.info("----------> 存储过程测试 start");
//        storageMapper.procDddRandomStorage();
//        log.info("----------> 存储过程测试 end");

        return storage;
    }

}
